package mo.leetcode_hot;

import mo.common.TreeNode;

public class L101 {

    public boolean isSymmetric(TreeNode root) {
        if ((root.left != null && root.right == null) || (root.left == null && root.right != null)) {
            return false;
        }
        if (root.left == null) {
            return true;
        }
        return two(root.left, root.right);
    }

    private boolean two(TreeNode left, TreeNode right) {
        if ((left != null && right == null) || (left == null && right != null)) {
            return false;
        }
        if (left == null) {
            return true;
        }
        return left.val == right.val && two(left.left, right.right) && two(left.right, right.left);
    }

}
